﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace NicoView.View
{
    /// <summary>
    /// ExceptionShowWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class ExceptionShowWindow : Window
    {
        public ExceptionShowWindow()
        {
            InitializeComponent();
        }

        public static void Show(Exception e)
        {
            SystemSounds.Hand.Play();
            var window = new ExceptionShowWindow();
            var stackTrace = new StackTrace(e, true);
            var message = "【例外】" + e.GetType().Name +"\r\n" +
                "【メッセージ】"+e.Message + "\r\n"+
                "【スタックトレース】" + e.StackTrace +"\r\n"+
                                    "【メソッド】" + e.TargetSite.Name + "\r\n";

            message += "【トレース情報】:\r\n";

            foreach (var stackFrame in stackTrace.GetFrames())
            {
                message += "【ファイル】" + stackFrame.GetFileName() + "\r\n";
                message += "【行番号】" + stackFrame.GetFileLineNumber() + "\r\n";
            }

            window.ErrorText.Text = message;

            window.ShowDialog();
        }
    }
}
